package com.samskievert.cactusboom;

import java.awt.Graphics;
import java.awt.Rectangle;
import java.awt.Dimension;
import java.awt.image.BufferedImage;

import javax.swing.JComponent;

import com.threerings.toybox.util.ToyBoxContext;

/**
 * Shiny background panel.
 *
 * Yay open source!  I borrowed this from Eric Woroshow's "High King"
 * http://www.gamegardens.com/gardens/view_game.wm?gameid=68
 */
public class bgPanel extends JComponent
{
    
	/**
	 * Creates a background panel and loads the associated images.
	 */
	public bgPanel(ToyBoxContext ctx) {
	    _bgTile = ctx.loadImage("media/bg.png");
            _bgCorner = ctx.loadImage("media/graphic.png");
	}
	
	@Override // from JComponent
	public void paintComponent(Graphics g) {
		Rectangle cbounds = getBounds();
		
		// tile the background image over the bounds of the component
		for (int x = 0; x < cbounds.getWidth(); x += _bgTile.getWidth()) {
			for (int y = 0; y < cbounds.getHeight(); y += _bgTile.getHeight()) {
				g.drawImage(_bgTile, x, y, null);
			}
		}
		
		// draw the corner piece
		g.drawImage(_bgCorner, 0, 0,(int)(cbounds.getWidth()/4),(int)(cbounds.getWidth()/4*2/3), null);
	}
    
   
    /** Tiled background image. */
    private BufferedImage _bgTile;
    
    /** Corner piece. */
    private BufferedImage _bgCorner;
}

